<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<jsp:include page="../common/common.jsp"></jsp:include>
<style>
	
	#inner01{
		width:500px;
		height:600px;
		margin:100px auto;
		overflow: hidden;
		display: none;
	}
	#inner02{
		width:500px;
		height:600px;
		margin:100px auto;
		overflow: hidden;
		display: none;
	}

</style>

</head>
<body>
	<div id="main01">
		<table id="dg" ></table>  
	</div>
	
	<div id="td">
		<a href="#" id="myadd" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
		<a href="#" id="mydel" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
		<a href="#" id="myupdate" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
		<input type="text" name="searchName" id="sea" />
		<a href="#" id="mysearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
	</div>
	
	<!-- 添加的弹出来的 -->
	<div id="dd">
		
		<div id="inner01">
	        
				
				
				 关于问题:<input name="problem" class="easyui-textbox" data-options="multiline:true,required:true" value="关于什么问题" style="width:170px;height:100px">
				  <br/><br/>
				 公告内容:<input name="content"   class="easyui-textbox" data-options="multiline:true,required:true" style="width:170px;height:100px" />
				 <br/><br/>
				 公告人:<input name="adminName"   class="easyui-validatebox" data-options="required:true" style="width:170px;height:20px" />
        		<br/><br/> 
        		 公告时间:<input name="time" id="time1" class="easyui-datetimebox"  data-options="required:true,validType:''"  style="width:170px;height:20px"> 
				 <br/><br/>
				
					
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="newadd" href="#" class="easyui-linkbutton" >添加</a>  
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="cz" href="#" class="easyui-linkbutton" >重置</a>  
	      </div>
	
	</div>  
	
	<!-- 修改的弹出来的 -->
	<div id="dd2">
		
		<div id="inner02">
	        
	       		<input type="text" name="id2" hidden="hidden"  />
				 关于问题:<input name="problem2" id="problem2" class="easyui-textbox" data-options="multiline:true,required:true"  style="width:170px;height:100px">
				  <br/><br/>
				 公告内容:<input name="content2"  id="content2"   class="easyui-textbox" data-options="multiline:true,required:true" style="width:170px;height:100px" />
				 <br/><br/>
				 公告人:<input name="adminName2"  id="adminName2"   class="easyui-validatebox" data-options="required:true" style="width:170px;height:20px" />
        		<br/><br/> 
        		 公告时间:<input name="time2" id="time2" class="easyui-datetimebox"  data-options="required:true,validType:''"  style="width:170px;height:20px"> 
				 <br/><br/>
					
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="newupdate" href="#" class="easyui-linkbutton" >修改</a>  
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a id="cz" href="#" class="easyui-linkbutton" >重置</a>  
	      </div>
	
	</div>  

	


<script type="text/javascript">

	$(function(){
		
		
		/*数据表*/
		
		$('#dg').datagrid({    
		    url:'${pageContext.request.contextPath}/notice/findWithPage',
		    fitColumns:true,
		    pagination:true,
		    toolbar:'#td',
		    pageNumber:1,
		    pageSize:4,
		    pageList:[4,8,16],
		    columns:[[    
		        {field:'id',title:'id',checkbox:true},    
		        {field:'problem',title:'关于问题',width:100},    
		        {field:'content',title:'公告内容',width:100},    
		        {field:'adminName',title:'公告人',width:100},    
		        {field:'time',title:'公告时间',width:100},    
		    ]]    
		});  

		/*总菜单 添加按钮*/
		
		$('#myadd').click(function(){
			
			$('#inner01').css("display","block");
			
			$('#dd').dialog({    
			    title: '添加',    
			    width: 800,    
			    height: 600,    
			    closed: false,    
			    cache: false,    
			    modal: true   
			});    
		});

		/*总菜单 添加按钮 弹出来的 提交按钮*/
		$('#newadd').click(function(){
			
			var a= $("input[name='problem']").val();
			var b= $("input[name='content']").val();
			var c= $("input[name='adminName']").val();
			var d= $("#time1").datetimebox('getValue');	
			
			
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/notice/addNotice',
				'data':{
					'problem':a,
					'content':b,
					'adminName':c,
					'time':d,
				},
				'success':function(msg){
					if(msg.code==200){
						
						$.messager.alert('提示','插入成功');    
						
						setTimeout(goMain(), 1000);
					}else if(msg.code==303){
						$.messager.alert('提示',"该记录已经存在"); 
					
					}else{
						$.messager.alert('提示','输入宿舍有误');    
					}
					
				},
			});
			 
		});
		
		/*总菜单删除的按钮 */
		$('#mydel').click(function(){
			var dels='';
			var obj=$('#dg').datagrid('getSelections');
			var a= $(obj).each(function(i,data){
				var aa=data.id;
				if(obj.length-1==i){
					dels=dels+aa;
				}else{
					dels=dels+aa+",";
				}
			});
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/notice/delNotice',
				'data':{
					'dles':dels,
				},
				'success':function(msg){
					if(msg.code==200){
						
						$.messager.alert('提示',"删除了"+msg.count+"条");
						setTimeout(goMain(), 1000);
					}else if(msg.code==201){
						
						$.messager.alert('提示',msg.msg);
					
					}else{
						$.messager.alert('提示',"删除失败");
					}
				},
			});
		});
		
		
		/*总菜单修改的按钮 */
		$('#myupdate').click(function(){
			
			/*只能选中一个*/
			var obj=$('#dg').datagrid('getSelections');
			if(obj.length==1){
				

				$('#inner02').css("display","block");
				/* 取到值 */
				var a= obj[0].id;
				var b= obj[0].problem;
				var c= obj[0].content;
				var d= obj[0].adminName;
				var e= obj[0].time;
				
				
				
				/* 赋值 */
				$("input[name='id2']").val(a);
				$("#problem2").textbox('setValue',b);
				$("#content2").textbox('setValue', c);
				$("#adminName2").val(d)
				$("#time2").datetimebox('setValue',e);	
				
				$('#dd2').dialog({    
				    title: '修改',    
				    width: 800,    
				    height: 600,    
				    closed: false,    
				    cache: false,    
				    modal: true   
				});    
			}else{
				$.messager.alert('提示','只能修改的一个');    
			}
			
			
			
		});
		
		/*总菜单修改的按钮 弹出来的提交的按钮*/
		$('#newupdate').click(function(){
			
			var id= $("input[name='id2']").val();
			var a= $("input[name='problem2']").val();
			var b= $("input[name='content2']").val();
			var c= $("input[name='adminName2']").val();
			var d= $("#time2").datetimebox('getValue');	
			
			$.ajax({
				'type':'post',
				'dateType':'json',
				'url':'${pageContext.request.contextPath}/notice/updateNotice',
				'data':{
					'id':id,
					'problem':a,
					'content':b,
					'adminName':c,
					'time':d,
				},
				'success':function(msg){
					if(msg.code==200){
						
						$.messager.alert('提示','更新成功'); 
						setTimeout(goMain(), 1000);
					}else if(msg.code==201){
						$.messager.alert('提示',msg.msg); 
					}else{
						$.messager.alert('提示','请认真确认要访问的宿舍和学生');
					}
					
				},
			});
			 
		});
		
		/*查询*/
		$('#mysearch').click(function(){
			var searchName1=$('#sea').val();
			
			$('#dg').datagrid('load', {    
			    'searchName':searchName1,
			});  

		});
		
		
/*结束*/
	});

		
	

	function goMain(){
		window.location.reload();
	}
	
	
</script>
</body>
</html>